package org.example.ims.Repository.Base;

import org.example.ims.Entity.Base.Salesman;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface SalesmanRepository extends JpaRepository<Salesman, Integer> {

    Salesman findBySalesmanName(String name);

    @Query("SELECT s FROM Salesman s " +
            "WHERE (:name IS NULL OR s.salesmanName = :name) " +
            "AND (:department IS NULL OR s.department = :department )" )
    Page<Salesman> searchSalesmen(@Param("name") String name,
                                   @Param("department") String department,
                                   Pageable pageable);
}
